/*
 * Freshtel FT-102 VoIP USB Phone driver
 *
 * Copyright (c) 2007 Sebastien Bourdeauducq <sebastien.bourdeauducq@gmail.com>
 * Copyright (c) 2005, 2006 Henk Vergonet <Henk.Vergonet@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef _FRESHTEL_H_
#define _FRESHTEL_H_

/* Packets received on the interrupt type. 
   Perhaps the device can send long packets there too. */

#define PAYLOAD_SHORT 11
   
struct ftd_packet_short {
	unsigned char cmd;			/* command code, see below */
	unsigned char size;			/* 0-11, size of used data bytes. */
	unsigned short int offset;		/* internal packet offset */
	unsigned char data[PAYLOAD_SHORT];
	signed char sum;			/* negative sum of 15 preceding bytes */
} __attribute__ ((packed));


/* When sending to the device, this packet must be used */

#define PAYLOAD_LONG 59

struct ftd_packet_long {
	unsigned char cmd;			/* command code, see below */
	unsigned char size;			/* 0-59, size of used data bytes. */
	unsigned short int offset;		/* internal packet offset */
	unsigned char data[PAYLOAD_LONG];
	signed char sum;			/* negative sum of 15 preceding bytes */
} __attribute__ ((packed));

#define USB_PKT_LEN	sizeof(struct ftd_packet_long)

/* The following yld_packet's are available: */

/* Initialization
 *
 * cmd		0x8e
 * size		0x0b
 * offset	0
 * data		all zeros when requesting, then strange codes received (device type/serial number ?)
 */
#define CMD_INIT		0x8e

/* Scancode. You must not send a request for this one, the device always sends them on its own.
 *
 * cmd		0x81
 * size		1
 * offset	key number [0-1f]
 * data[0]	scancode
 */
#define CMD_SCANCODE		0x81

/* Set LCD
 *
 * cmd		0x04
 * size		1-59
 * offset	0-?
 * data		framebuffer data
 */
#define CMD_LCD			0x04

#define LCD_W			104
#define LCD_H			48
#define LCD_CHUNKSIZE		44
#define LCD_BUFSIZE		((LCD_W*LCD_H)/8)
#define LCD_CHUNKCOUNT		((LCD_BUFSIZE+LCD_CHUNKSIZE-1)/LCD_CHUNKSIZE)
#define LCD_LASTCHUNKSIZE	(LCD_BUFSIZE % LCD_CHUNKSIZE)

/* LCD backlight control
 *
 * cmd      0x12
 * size     1
 * offset   0
 * data[0]  0 OFF / 1 ON
 * data[0]  returns last key scan code (???)
 */
#define CMD_LCD_BACKLIGHT	0x05

/* Set led
 *
 * cmd		0x05
 * size		1
 * offset	0
 * data[0]	0 OFF / 1 ON
 */
#define CMD_LED			0x05

/* Set ringtone volume
 *
 * cmd		0x11
 * size		1
 * offset	0
 * data[0]	0-0xff  volume
 */
#define CMD_RING_VOLUME		0x11

/* Set ringtone notes
 *
 * cmd		0x02
 * size		1-11
 * offset	0->
 * data		binary representation LE16(-freq), LE16(duration) ....
 */
#define CMD_RING_NOTE		0x02

/* Sound ringtone via the speaker on the back
 *
 * cmd		0x03
 * size		1
 * offset	0
 * data[0]	number of rings, 0 = turn off
 */
#define CMD_RING		0x03

#endif /* _FRESHTEL_H_ */

